package com.file_.fileoutput_;

import java.io.FileOutputStream;
import java.io.IOException;

/*
    使用FileOutputStream写入指定长度的字符串
 */
public class Demo5 {
    public static void main(String[] args) {
        String fielPath = "D:\\A_Test\\a.txt";
        FileOutputStream fileOutputStream = null;
        try {
            fileOutputStream = new FileOutputStream(fielPath);
            // 写入字符串
            String str = "hello,world!";
            // write(byte[] b, int off, int len) 将len字节从位于偏移量off的指定字节数组写入此文件流
            fileOutputStream.write(str.getBytes(), 0, str.length());
            System.out.println("写入成功");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
